package com.rattsoftware.client.controllers;

import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.event.EventType;
import com.extjs.gxt.ui.client.mvc.AppEvent;
import com.extjs.gxt.ui.client.mvc.Controller;
import com.google.gwt.core.client.GWT;
import com.rattsoftware.client.AppMessages;
import com.rattsoftware.client.webclient;
import com.rattsoftware.client.events.AppEvents;
import com.rattsoftware.client.service.DepartmentServiceAsync;
import com.rattsoftware.client.service.FacultyServiceAsync;
import com.rattsoftware.client.service.UserServiceAsync;
import com.rattsoftware.client.views.NewEditDepartmentView;

public class NewEditDepartmentController extends Controller {

	AppMessages appMessages = GWT.create(AppMessages.class);

	private FacultyServiceAsync facultyService;
	private DepartmentServiceAsync departmentService;
	private UserServiceAsync userService;
	private NewEditDepartmentView newEditDepartmentView;

	public NewEditDepartmentController() {
		super();
		userService = Registry.get(webclient.USER_SERVICE);
		facultyService = Registry.get(webclient.FACULTY_SERVICE);
		departmentService = Registry.get(webclient.DEPARTMENT_SERVICE);
		registerEventTypes(AppEvents.NewDepartment);
		registerEventTypes(AppEvents.EditDepartment);
	}
	
	public void initialize() {
		GWT.log("NewEditDepartmentController : initialize");
		super.initialize();
		newEditDepartmentView = new NewEditDepartmentView(this);
	}

	@Override
	public void handleEvent(AppEvent event) {
		GWT.log("NewEditDepartmentController : handleEvent");
		EventType type = (EventType) event.getType();
		if (type == AppEvents.NewDepartment) {
			forwardToView(newEditDepartmentView, event);
		} else if (type == AppEvents.EditDepartment) {
			forwardToView(newEditDepartmentView, event);
		}
	}
}
